Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tailwind + shadcn/ui. #888

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Emt-lin
Copy link
Contributor

@Emt-lin Emt-lin commented Dec 2, 2024

No description provided.

styles.css Outdated
max-width: 1536px;
}
}
.visible {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this file be checked in? It looks like the generated tailwind CSS file


*/

.button-container {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these styles?


@layer base {
:root {
--background: 0 0% 100%;
Copy link
Contributor

@zeroliu zeroliu Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make UI library compatible with obsidian plugin, we should use the CSS variables defined in obsidian (https://docs.obsidian.md/Reference/CSS+variables/CSS+variables). Many obsidian users use themes, which are made by altering those CSS variables (https://docs.obsidian.md/Themes/App+themes/Build+a+theme). Users would expect a well-designed plugin to change the appearance accordingly.

This is the main reason why I believe shadcn is the right choice for obsidian plugin UI library. It provides developer great flexibility to change how components are styled. However, we will lose the value if we use the shadcn default CSS variables.

I suggest:

  1. Do not introduce new CSS variables
  2. update tailwind.config.js to create tokens that map to obsidian CSS variables, including color, spacing, sizing, etc
  3. whenever we introduce a shadcn component, restyle it with the new token before we integrate it into the plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeroliu sometimes, I don't want to use some of the built-in theme styles.(eg: radius)
so, I think we should select some css styles to map.

@logancyang
Copy link
Owner

I checked out this branch and ran locally, it seems to override some obsidian native CSS vars
SCR-20241203-seis

@Emt-lin
Copy link
Contributor Author

Emt-lin commented Dec 4, 2024

@logancyang @zeroliu

now, style.css is already generated by tailwind cli. The original traditional css style are intailwind.css file. Perhaps We should make these traditional css style into tailwind style.

@logancyang
Copy link
Owner

@logancyang @zeroliu

now, style.css is already generated by tailwind cli. The original traditional css style are intailwind.css file. Perhaps We should make these traditional css style into tailwind style.

Is this going to be quite a big effort to make everything look the same/similar? I'm not familiar with how it can be converted though. @zeroliu is the expert here I'll wait for his recommendation.

@Emt-lin Emt-lin force-pushed the UI branch 2 times, most recently from e031a19 to a848f01 Compare December 4, 2024 10:48
@Emt-lin
Copy link
Contributor Author

Emt-lin commented Dec 4, 2024

@logancyang @zeroliu
now, style.css is already generated by tailwind cli. The original traditional css style are intailwind.css file. Perhaps We should make these traditional css style into tailwind style.

Is this going to be quite a big effort to make everything look the same/similar? I'm not familiar with how it can be converted though. @zeroliu is the expert here I'll wait for his recommendation.

I already delete styles.css file in latest commit, it will be created by tailiwind cli When you are running npm run dev or build

src/styles/tailwind.css Outdated Show resolved Hide resolved
package.json Outdated
"dev": "npm-run-all --parallel dev:*",
"dev:tailwind": "npx tailwindcss -i src/styles/tailwind.css -o ./styles.css --watch",
"dev:esbuild": "node esbuild.config.mjs",
"build:tailiwind": "npx tailwindcss -i src/styles/tailwind.css -o ./styles.css --minify",
Copy link
Owner

@logancyang logancyang Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: build:tailiwind. I recommend some form of AI assistance to spot these things in the future. It's hard for reviewers to spot.

package.json Outdated
"dev:tailwind": "npx tailwindcss -i src/styles/tailwind.css -o ./styles.css --watch",
"dev:esbuild": "node esbuild.config.mjs",
"build:tailiwind": "npx tailwindcss -i src/styles/tailwind.css -o ./styles.css --minify",
"build": "npm run build:tailiwind && tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like

{
  "scripts": {
    "build:tailwind": "npx tailwindcss -i src/styles/tailwind.css -o ./styles.css --minify",
    "build:esbuild": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
    "build": "npm run build:tailwind && npm run build:esbuild || exit 1"
  }
}

@logancyang
Copy link
Owner

logancyang commented Dec 5, 2024

Awesome job! The UI now looks correct to me.

One concern is that the bundle size is up significantly from 5MB+ to 21MB+. Is there any way we can make it smaller?

Tailwind purging?

Copy link
Contributor

@zeroliu zeroliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some more comments. Looking good overall! Looking forward to using tailwindCSS in the near future

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this file?

preflight: false,
},
theme: {
extend: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not extend but redefine all the tokens? Otherwise, people can still use predefined tailwind tokens without realizing that it's not connected to obsidian CSS variables. We can also turn on this eslint rule to enforce only supported classnames are used in the code base: https://github.com/francoismassart/eslint-plugin-tailwindcss/blob/master/docs/rules/no-custom-classname.md

<input
type={type}
className={cn(
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we support file type input? If not, I suggest not adding the related style until it's needed


import { cn } from "@/lib/utils";

const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocking this PR but maybe we can look into React 19 and use the ref props now that it's officially GA. Maintaining forwardRef for RadixUI can be pretty tedious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants